/**
 * Copyright (c) 2010-2020 by skzr.org
 * All rights reserved.
 * @Author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @date 2011-3-14 下午09:16:15
 */
package org.skzr.logging;

import java.util.Locale;

import org.junit.Assert;
import org.junit.Test;


/**
 * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @version 1.0.0
 * @since JDK1.6
 */
public class LocalLoggerTestCase {
	private final transient ILocalLogger logger = LocalLoggerFactory.getLogger(getClass());
	
	@Test
	public void testLocalLoggerFactory() {
		Assert.assertSame(logger, LocalLoggerFactory.getLogger(getClass()));
	}
	
	@Test
	public void testLocalLog() {
		Assert.assertNotNull(logger);
		logger.trace("{}->{}", "编码", "文件");
		logger.trace(MsgLocalLog.LOAD_PROPERTIES_FAILED, "编码", "文件");
		logger.trace(MsgLocalLog.LOAD_PROPERTIES_FAILED, "编码", "文件", new UnsupportedOperationException("我日"));
	}
	
	@Test
	public void testDefaultMsgLog() {
		Assert.assertEquals("[青蛙, 王子]", logger.getText(MsgLocalLog.NOT_EXIST, "青蛙", "王子"));
	}
	
	@Test
	public void testLocalException() {
		try {
			Locale.setDefault(Locale.CHINA);
			throw new IllegalArgumentException(
					LocalLoggerFactory.getLogger("china").getText(MsgLocalLog.EXCEPTION_MSG1, "青蛙", "王子"), null);
		} catch (Exception e) {
			Assert.assertEquals("我的异常消息：青蛙是王子。", e.getLocalizedMessage());
		}
		
		try {
			Locale.setDefault(Locale.US);
			throw new IllegalArgumentException(
					LocalLoggerFactory.getLogger("us").getText(MsgLocalLog.EXCEPTION_MSG1, "青蛙", "王子"), null);
		} catch (Exception e) {
			Assert.assertEquals("Hi guys, exception message is : 王子 from 青蛙", e.getLocalizedMessage());
		}
		
		try {
			Locale.setDefault(Locale.JAPAN);
			throw new IllegalArgumentException(
					LocalLoggerFactory.getLogger("japan").getText(MsgLocalLog.EXCEPTION_MSG1, "青蛙", "王子"), null);
		} catch (Exception e) {
			Assert.assertEquals("Hi guys, exception message is : 王子 from 青蛙", e.getLocalizedMessage());
		}
	}
	
}
